<template>
  <div class="content-block">
    <div class="info-head">{{ title }}</div>
    <div class="info-content">
      <v-chart
        ref="chart" :option="chartOption" style="width:672px;height:500px;"
        :theme="chartTheme" autoresize
      ></v-chart>
    </div>
  </div>
</template>

<script>
import ChartResizeListener from '@/mixins/chart-resize-listener'
import BarClickListener from '@/mixins/bar-click-listener'
import MixinVchartTheme from '@/mixins/mixin-vchart-theme';

export default {
  name: 'grid-item-three',
  mixins: [ChartResizeListener, BarClickListener, MixinVchartTheme],
  props: {
    title: String,
  },
  data () {
    return {
      info: []
    }
  },
  computed: {
    districts () {
      return this.$store.getters['user/districts']
    },
    themeColor () {
      return this.$store.state.user.theme
    },
    chartOption () {
      return {
        color: this.themeColor,
        grid: {
          bottom: '40px',
          containLabel: true
        },
        tooltip: {
          trigger: 'item'
        },
        yAxis: {
          type: 'value',
          name: '吨标准煤'
        },
        xAxis: {
          type: 'category',
          data: this.districts.map(v => v.name),
        },
        series: [
          {
            type: 'bar',
            data: this.districts.map(v => ({
              code: v.code,
              name: v.name,
              value: Math.round(Math.random() * 100),
            }))
          }
        ]
      }
    }
  },
}
</script>
